Skip to main content

Sprite Class

Description:

  A class used for creating Sprite object.

Usage:

local Sprite = require("Sprite")
local sprite = Sprite("Image/file.png")

getClips

Type: Function.

Description:

  Gets the clip names and rectangles from the clip file.

Signature:

getClips: function(self: SpriteClass, clipFile: string): {string: Rect} | nil

Parameters:

ParameterTypeDescription
clipFilestringThe clip file name to load, should end with ".clip".

Returns:

Return TypeDescription
{string: Rect} | nilA table containing the clip names and rectangles.

__call

Type: Metamethod.

Description:

  A metamethod for creating Sprite object.

Signature:

metamethod __call: function(self: SpriteClass, clipStr: string): Sprite | nil

Parameters:

ParameterTypeDescription
clipStrstringThe string containing format for loading a texture file.Can be "Image/file.png" and "Image/items.clip

Returns:

Return TypeDescription
Sprite | nilA new instance of the Sprite class. If the texture file is not found, it will return nil.

__call

Type: Metamethod.

Description:

  A metamethod for creating Sprite object.

Signature:

metamethod __call: function(self: SpriteClass): Sprite

Returns:

Return TypeDescription
SpriteA new instance of the Sprite class.

__call

Type: Metamethod.

Description:

  A metamethod for creating Sprite object.

Signature:

metamethod __call: function(self: SpriteClass, texture: Texture2D, textureRect?: Rect): Sprite

Parameters:

ParameterTypeDescription
textureTexture2DThe texture to be used for the sprite.
textureRectRect[optional] The rectangle defining the portion of the texture to use for the sprite, if not provided, the whole texture will be used for rendering.

Returns:

Return TypeDescription
SpriteA new instance of the Sprite class.